//
//  RempayResultViewController.m
//  Rong360
//
//  Created by tianliwei on 16/2/14.
//  Copyright (c) 2014 tianliwei. All rights reserved.
//

#import "RempayResultViewController.h"
#import "PayResultCell.h"
#import "WebViewController.h"
@interface RempayResultViewController ()
@property (nonatomic, strong) NSArray *results;
@property (nonatomic, strong) NSArray *titles;
@property (nonatomic, strong) NSArray *subTitles;
@end
static NSString *CellIdentifier = @"Cell";
@implementation RempayResultViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (id)initWithResults:(NSArray *)results{
    self = [super init];
    if (self) {
        self.results = results;
    }
    return self;
}

- (void)initTableFooterView{
    UIView *tableFooterView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, UI_SCREEN_WIDTH, 100)];
    UILabel *label = [UILabel labelWithFrame:CGRectMake(12, 10, 300, 15) title:@"以上结果仅供参考，请以当地实际情况为准" fontColor:[UIColor lightGrayColor] fontSize:10];
    UIButton *reCal = [UIButton buttonWithTag:1 frame:CGRectMake(15, 45, 135, 35) normalImage:[UIImage imageNamed:@"btn_qd_normal"] highlightedImage:[UIImage imageNamed:@"btn_qd_focus"] target:self action:@selector(buttonClicked:)];
    [reCal setTitle:@"重新计算" forState:UIControlStateNormal];
    [reCal.titleLabel setFont:[UIFont systemFontOfSize:14]];
    UIButton *sendResult = [UIButton buttonWithTag:2 frame:CGRectMake(170, 45, 135, 35) normalImage:[UIImage imageNamed:@"btn_tg_normal"] highlightedImage:[UIImage imageNamed:@"btn_tg_focus"] target:self action:@selector(buttonClicked:)];
    [sendResult setTitle:@"发送结果" forState:UIControlStateNormal];
    [sendResult.titleLabel setFont:[UIFont systemFontOfSize:14]];
    [tableFooterView addSubview:label];
    [tableFooterView addSubview:reCal];
    [tableFooterView addSubview:sendResult];
    self.tableView.tableFooterView = tableFooterView;
}

- (void)buttonClicked:(UIButton *)sender{
    switch (sender.tag) {
        case 0:{
            
        }
        case 1:{
            [self.navigationController popViewControllerAnimated:YES];
            break;
        }
        case 2:{
            NSString *shareText = [NSString stringWithFormat:@"我在#融360买房助手#中测得我的贷款还有%@元未还，这个应用真的很强大，用了之后，基本不怕被中介忽悠了，你也来试试吧",self.results[0]];
            [UMSocialData defaultData].extConfig.wxMessageType = UMSocialWXMessageTypeWeb;
            [UMSocialWechatHandler setWXAppId:kWXAppID url:kRong360Host];
            [UMSocialConfig setQQAppId:kTencentID url:kRong360Host importClasses:@[[QQApiInterface class],[TencentOAuth class]]];
//            [UMSocialConfig setShareQzoneWithQQSDK:YES url:kRong360Host importClasses:@[[QQApiInterface class],[TencentOAuth class]]];
            [UMSocialSnsService presentSnsIconSheetView:self
                                                 appKey:kUMSocialKey
                                              shareText:shareText
                                             shareImage:[UIImage imageNamed:kShareIcon]
                                        shareToSnsNames:[NSArray arrayWithObjects:UMShareToSina,UMShareToTencent,UMShareToRenren,UMShareToWechatSession,UMShareToWechatTimeline,UMShareToQQ,nil]
                                               delegate:nil];
            break;
        }
        default:
            break;
    }
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    self.view.backgroundColor = [UIColor whiteColor];
    self.tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, UI_SCREEN_WIDTH, UI_NAVIFRAME_HEIGHT)];
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    NSInteger rowHeight = 50;
    self.tableView.rowHeight = rowHeight;
    self.tableView.scrollEnabled = YES;
    self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    [self.tableView registerNib:[UINib nibWithNibName:@"PayResultCell" bundle:nil] forCellReuseIdentifier:CellIdentifier];
    [self initTableFooterView];
    [self.view addSubview:self.tableView];
//    [self initTableFooterView];
    self.title = @"计算结果";
    self.titles = @[@"剩余还款总额:",@"剩余本金:",@"剩余利息:",@"已还本金:",@"已还利息"];
    self.subTitles = @[@"元",@"元",@"元",@"元",@"元"];
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    // Return the number of sections.
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    // Return the number of rows in the section.
    return self.titles.count;
}

//- (NSString *)tableView:(UITableView *)tableView titleForFooterInSection:(NSInteger)section{
//    return @"";
//}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{

    PayResultCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    cell.mainLabel.text = self.titles[indexPath.row];
    NSString *result = [NSString stringWithFormat:@"%@",self.results[indexPath.row]];
    cell.subLabel.text = result;
    cell.unitLabel.text = self.subTitles[indexPath.row];
    if (indexPath.row == 0) {
        cell.subLabel.textColor = [UIColor redColor];
    }else{
        cell.subLabel.textColor = APPCOLOR;
    }
    // Configure the cell...
    return cell;
    
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
